<!-- components/ui/ModalLoader.vue -->
<template>
    <div class="modal-loader-overlay">
      <div class="modal-loader-container">
        <!-- 加载动画 -->
        <div class="loading-spinner">
          <div class="spinner-ring"></div>
          <div class="spinner-ring"></div>
          <div class="spinner-ring"></div>
          <div class="spinner-ring"></div>
        </div>
        
        <!-- 加载文本 -->
        <div class="loading-text">
          <slot>
            <p>组件加载中...</p>
            <p class="loading-subtext">请稍候</p>
          </slot>
        </div>
        
        <!-- 进度指示器（可选） -->
        <div v-if="showProgress" class="progress-indicator">
          <div class="progress-bar">
            <div 
              class="progress-fill" 
              :style="{ width: progress + '%' }"
            ></div>
          </div>
          <span class="progress-text">{{ progress }}%</span>
        </div>
      </div>
    </div>
  </template>
  
  <script setup lang="ts">
  interface ModalLoaderProps {
    // 是否显示进度指示器
    showProgress?: boolean
    // 加载进度（0-100）
    progress?: number
    // 加载状态文本
    message?: string
  }
  
  withDefaults(defineProps<ModalLoaderProps>(), {
    showProgress: false,
    progress: 0,
    message: '组件加载中...'
  })
  
  // 模拟进度动画（可选）
  const animatedProgress = ref(0)
  let progressInterval: NodeJS.Timeout
  
  onMounted(() => {
    if (props.showProgress) {
      progressInterval = setInterval(() => {
        animatedProgress.value = Math.min(animatedProgress.value + 10, props.progress)
        if (animatedProgress.value >= 100) {
          clearInterval(progressInterval)
        }
      }, 200)
    }
  })
  
  onUnmounted(() => {
    if (progressInterval) {
      clearInterval(progressInterval)
    }
  })
  </script>
  
  <style scoped>
  .modal-loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    animation: fadeIn 0.3s ease-in-out;
  }
  
  .modal-loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 40px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.1);
    min-width: 280px;
    max-width: 90vw;
  }
  
  /* 加载动画样式 */
  .loading-spinner {
    position: relative;
    width: 64px;
    height: 64px;
  }
  
  .spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
  }
  
  .spinner-ring:nth-child(1) {
    border-top-color: #667eea;
    animation-delay: 0s;
  }
  
  .spinner-ring:nth-child(2) {
    border-right-color: #764ba2;
    animation-delay: 0.1s;
  }
  
  .spinner-ring:nth-child(3) {
    border-bottom-color: #f093fb;
    animation-delay: 0.2s;
  }
  
  .spinner-ring:nth-child(4) {
    border-left-color: #f5576c;
    animation-delay: 0.3s;
  }
  
  /* 文本样式 */
  .loading-text {
    text-align: center;
  }
  
  .loading-text p {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
    color: #333;
  }
  
  .loading-subtext {
    font-size: 14px;
    color: #666;
    margin-top: 8px !important;
  }
  
  /* 进度条样式 */
  .progress-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 200px;
  }
  
  .progress-bar {
    width: 100%;
    height: 6px;
    background: #f0f0f0;
    border-radius: 3px;
    overflow: hidden;
  }
  
  .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea, #764ba2);
    border-radius: 3px;
    transition: width 0.3s ease;
  }
  
  .progress-text {
    font-size: 12px;
    color: #666;
    font-weight: 500;
  }
  
  /* 动画定义 */
  @keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }
  
  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }
  
  /* 响应式设计 */
  @media (max-width: 768px) {
    .modal-loader-container {
      padding: 24px;
      gap: 20px;
    }
    
    .loading-spinner {
      width: 48px;
      height: 48px;
    }
    
    .loading-text p {
      font-size: 14px;
    }
  }
  
  /* 深色模式支持 */
  @media (prefers-color-scheme: dark) {
    .modal-loader-overlay {
      background: rgba(0, 0, 0, 0.8);
    }
    
    .modal-loader-container {
      background: #1f1f1f;
      border-color: rgba(255, 255, 255, 0.1);
    }
    
    .loading-text p {
      color: #fff;
    }
    
    .loading-subtext {
      color: #ccc;
    }
    
    .progress-bar {
      background: #333;
    }
  }
  </style>